#!/bin/bash

if [[ $1 != "get" ]]; then
    exit 1
fi

read inputLine

if [[ $inputLine == "registry2.example.com" ]]; then
    echo Fake credentials not found on credentials store \'$inputLine\' 1>&2
    exit 1
fi
if [[ $inputLine == "https://not.a.real.registry/url" ]]; then
    echo Fake credentials not found on credentials store \'$inputLine\' 1>&2
    exit 1
fi

if [[ $inputLine == "registry.example.com" ]]; then
    echo '{' \
        '  "ServerURL": "url",' \
        '  "Username": "username",' \
        '  "Secret": "secret"' \
        '}'
    exit 0
fi
if [[ $inputLine == "registrytoken.example.com" ]]; then
    echo '{' \
        '  "ServerURL": "url",' \
        '  "Username": "<token>",' \
        '  "Secret": "secret"' \
        '}'
    exit 0
fi

exit 1
